//
//  WJCustomOperationButton.swift
//  PDFSign
//
//  Created by 李永彬 on 2025/9/28.
//

import UIKit
// 自定义操作按钮类
class WJCustomOperationButton: UIControl {
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.montserratRegular(16)
        label.textColor = UIColor(hex: "#121212")
        return label
    }()
      
    private let iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
      
    init(title: String, imageName: String) {
        super.init(frame: .zero)
        commonInitSubViews()
        updateButton(title: title, imageName: imageName)
    }
    
    func commonInitSubViews() {
        
        addSubview(titleLabel)
        addSubview(iconImageView)
  
        titleLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12)
            make.centerY.equalToSuperview()
        }
          
        iconImageView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }
    }
      
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
      
    private func updateButton(title: String, imageName: String) {
        titleLabel.textColor = title == "Delete" ? UIColor(hex: "#FF2C2C") : UIColor(hex: "#121212")
        titleLabel.text = title
        if let image = UIImage(named: imageName) {
            iconImageView.image = image
        }
    }
}


